home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 3.6 KB | 154 lines | [TEXT/MPS ] |
- /*
- File: Document.cp
-
- Contains: TDocument implementation.
-
- Copyright: © 1991-1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __DOCUMENT__
- #include "Document.h"
- #endif
-
- /**********************************************************************
- ** TDocument
- ***********************************************************************/
-
- TDocument::TDocument()
- {
- fDocWindow = NULL;
- fDocList = NULL;
- }
-
- TDocument::TDocument(short resID)
- {
- InitDocument(resID);
- }
-
- TDocument::~TDocument(void)
- {
- if (fDocList)
- fDocList->RemoveDoc(this);
- DisposeWindow(fDocWindow);
- }
-
- void TDocument::InitDocument(short resID)
- {
- long savedRefNum;
- GetLocalLibraryFile()->Preflight(savedRefNum);
- fDocWindow = GetNewWindow(resID,NULL,(WindowPtr) -1);
- #if qDebug
- if (!fDocWindow)
- DebugStr((ConstStr255Param)"\pTDocument::InitDocument could not GetNewWindow\n");
- #endif
- GetLocalLibraryFile()->Postflight(savedRefNum);
-
- if (fDocWindow)
- SetPort(fDocWindow);
- fDocList = NULL;
- }
-
- void TDocument::DoZoom(short) {};
- void TDocument::DoGrow(EventRecord*) {};
- void TDocument::DoContent(EventRecord*) {};
- void TDocument::DoKeyDown(EventRecord*) {};
- void TDocument::DoActivate(Boolean) {};
- void TDocument::DoUpdate() {};
- void TDocument::DoOpen() {};
- void TDocument::DoClose() { delete this; };// by default, we just delete ourself & let destructor do cleanup
- void TDocument::DoSave() {};
- void TDocument::DoSaveAs() {};
- void TDocument::DoRevert() {};
- void TDocument::DoPrint() {};
- void TDocument::DoUndo() {};
- void TDocument::DoCut() {};
- void TDocument::DoCopy() {};
- void TDocument::DoPaste() {};
- void TDocument::DoClear() {};
- void TDocument::DoSelectAll() {};
- void TDocument::DoIdle() {};
- unsigned long TDocument::CalcIdle() { return kMaxSleepTime; }; // by default, we don't need idle
- void TDocument::AdjustCursor(Point) {}; // where is in local coords
- Boolean TDocument::HaveUndo() { return false; };
- Boolean TDocument::HaveSelection() { return false; };
- Boolean TDocument::HavePaste() { return false; };
- Boolean TDocument::CanClose() { return true; };
- Boolean TDocument::CanSave() { return false; };
- Boolean TDocument::CanSaveAs() { return true; };
- Boolean TDocument::CanRevert() { return false; };
- Boolean TDocument::CanPrint() { return false; };
-
- /**********************************************************************
- ** TDocumentList
- ***********************************************************************/
-
- TDocumentList::TDocumentList()
- {
- fDocList = NULL;
- fNumDocs = 0;
- }
-
- TDocumentList::~TDocumentList()
- {
- /* destroy all our documents */
-
- while (fDocList) {
- TDocument *theDoc = fDocList->GetDoc();
- RemoveDoc(theDoc);
- theDoc->DoClose();
- }
- }
-
- // find the TDocument associated with the window
- TDocument* TDocumentList::FindDoc(WindowPtr window)
- {
- TDocumentLink* temp;
- TDocument* tDoc;
-
- for (temp = fDocList; temp != NULL; temp = temp->GetNext())
- {
- tDoc = temp->GetDoc();
- if (tDoc->GetDocWindow() == window)
- return tDoc;
- }
- return NULL;
- }
-
- // private list management routines
- void TDocumentList::AddDoc(TDocument* doc)
- {
- TDocumentLink* temp;
-
- temp = new TDocumentLink(fDocList,doc);
- fDocList = temp;
- doc->SetDocList(this);
- fNumDocs++;
- }
-
- void TDocumentList::RemoveDoc(TDocument* doc)
- {
- TDocumentLink* temp;
- TDocumentLink* last;
-
- last = NULL;
- for (temp = fDocList; temp != NULL; temp = temp->GetNext()) {
- if (temp->GetDoc() == doc)
- {
- if (last == NULL) // if first item in list, just set first
- fDocList = temp->GetNext();
- else
- last->SetNext(temp->GetNext());
- delete temp;
- fNumDocs--;
- doc->SetDocList(NULL);
- return;
- }
- else last = temp;
- }
- }
-